import Vue from 'vue';
const that = Vue.prototype
/**
 * 1-flag1、选择的row集合里，有row的authDepartments为空，不通过，提示‘归属部门信息为空’
 * 2-flag2、选择的row集合里，有row的authDepartments为多个，不通过，提示‘商品拥有多个归属部门’
 * 3-flag3、选择的row集合里，有row的authDepartments和其他row的不同，不通过，‘归属部门不一致不能同时发起’
 */
/* 校验归属部门方法 */
export const judgeAuthDepartmentFn = (tableData) => {
  let flag1 = _.some(tableData, item => { return (!item.authDepartments || item.authDepartments.length === 0) })
  if (flag1) {
    that.$message.warning('归属部门信息为空')
    return false
  }
  let flag2 = _.some(tableData, item => { return item.authDepartments.length > 1 })
  if (flag2) {
    that.$message.warning('商品拥有多个归属部门')
    return false
  }
  let authDepartmentsList = (!flag1 && !flag2) && tableData.map(value => {
    return value.authDepartments[0].hrDepartmentNumber
  })
  let flag3 = new Set(authDepartmentsList).size !== 1
  if (flag3) {
    that.$message.warning('归属部门不一致不能同时发起')
    return false
  }
  return true
}
